#!/usr/bin/env python
# _*_coding:utf-8_*_

from PySide6.QtCore import *
from driver.e5080b_driver import ENADriver
import time
from my_log.logger import logger


class Signal(QObject):
    resultSignal = Signal(int, object)
    finishSignal = Signal()


class MeasurementThread(QRunnable):
    def __init__(self, address):
        super(MeasurementThread, self).__init__()
        self.singal = Signal()
        self._isPause = False
        self.status = 0
        self.isStart = False
        self.cond = QWaitCondition()

        self.mutex = QMutex()
        self.flag = True
        self.address = address
        self.inst = ENADriver(self.address)

    def run(self):
        try:
            self.mutex.lock()
            while self.flag:
                self.pause()
                if self._isPause:
                    self.cond.wait(self.mutex)
                result_list = self.inst.get_marker_value([1, 2, 3, 4])
                self.singal.resultSignal.emit(1, result_list)
                self.singal.finishSignal.emit()
            self.mutex.unlock()
        except Exception as e:
            logger.error("MeasurementThread," + str(e))



    def pause(self):
        self._isPause = True

    def resume(self):
        self._isPause = False
        self.cond.wakeAll()

    def stop(self):
        self.flag = False
